package com.mall.shopping.services;

import com.mall.shopping.IHomeService;
import com.mall.shopping.constants.ShoppingRetCode;
import com.mall.shopping.converter.PanelConverter;
import com.mall.shopping.dal.entitys.Panel;
import com.mall.shopping.dal.persistence.item.PanelMapperByMP;
import com.mall.shopping.dto.HomePageResponse;
import com.mall.shopping.dto.PanelDto;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;
import java.util.Set;

/**
 * 类<code>Doc</code>用于：TODO
 *
 * @author Acher
 * @version 1.0
 * @date 2021-10-31
 */
@Service
public class IHomeServiceImpl implements IHomeService {

    @Autowired
    PanelMapperByMP panelMapper;
    @Autowired
    PanelConverter panelConverter;

    @Override
    public HomePageResponse homepage() {
        HomePageResponse response = new HomePageResponse();
        try {
            List<Panel> panels = panelMapper.selectAllPanel();
            List<PanelDto> panelDtos = panelConverter.panelDO2DTO(panels);
            response.setCode(ShoppingRetCode.SUCCESS.getCode());
            response.setMsg(ShoppingRetCode.SUCCESS.getMessage());
            response.setPanelContentItemDtos(panelDtos);
        } catch (Exception e) {
            e.printStackTrace();
            response.setCode(ShoppingRetCode.DB_EXCEPTION.getCode());
            response.setMsg(ShoppingRetCode.DB_EXCEPTION.getMessage());
        }
        return response;
    }
}
